package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Comallocation;
import cn.wolfcode.crm.service.IComallocationService;
import cn.wolfcode.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;


@Controller
@RequestMapping("/comallocation")
public class ComallocationController {
    @Autowired
    private IComallocationService comallocationService;

    @RequestMapping("")
    public String index() {
        return "comallocation";
    }


    @RequestMapping("list")
    @ResponseBody
    public List<Comallocation> list(Model model) {
        return comallocationService.list();
    }

    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Integer mixNumber, Date time) {
        Comallocation comallocation = new Comallocation();
        comallocation.setNumBer(mixNumber);
        comallocation.setTime(time);
        JsonResult jsonResult = new JsonResult();
        try {
            comallocationService.save(comallocation);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonResult;
    }

    @RequestMapping("update")
    @ResponseBody

    public JsonResult update(Comallocation comallocation) {
        JsonResult jsonResult = new JsonResult();
        try {
            comallocationService.update(comallocation);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonResult;
    }

    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        JsonResult jsonResult = new JsonResult();
        try {
            comallocationService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonResult;
    }


}
